const http = require("http");
const server = http.createServer((req, res) => {
  res.setHeader("Content-type", "text/html;charset=utf-8"); // 支持中文
  /**
   * 请求行实例化（便于查询协议名、主机名、端口号、路径、查询字符串
   * 参数1 = 路径+查询字符串
   * 参数2 = 协议+主机名+端口号(省略)
   * /search?a=100&b=200&c=300
   */
  const urlInstance = new URL(req.url, "http://localhost:8080");
  console.log("实例化 URL：", urlInstance);
  console.log("查询字符串：", urlInstance.searchParams.get("a")); // 查询字符串 a
  res.end();
});
server.listen(8080);
